<template>
    <view class="pageContainer">
        <image v-show="banner===1" class="navBg" mode="widthFix" src="../images/banner.png" />
        <image v-show="banner!==1" class="navBg" mode="widthFix" src="../images/banner2.png" />
    </view>
    <view v-if="backisShow===0?false:true" @click="back" class="backbtn">
        返回
    </view>
    <text v-if="backisShow===1?false:true" class="noBackText">元创笔</text>
</template>
<script setup>
import Taro from '@tarojs/taro';
import { useBluetoothStore } from '../store/blueTooth'
const { 
    state, 
    stopBluetoothDevicesDiscovery,
    resetState,
    closeBluetoothAdapter
} = useBluetoothStore()

defineProps(['backisShow','banner'])

function back() {
    console.log('state.discoveryStarted:::',state.discoveryStarted)
    const pages = Taro.getCurrentPages();
    const prevPage = pages[pages.length - 2];  // 获取上一个页面
    const prevRoute = prevPage.route;          // 获取上一个页面的路径
    const currentPage = pages[pages.length - 1];   // 获取栈顶页面
    const currentPath = currentPage.route;   // 当前页面的路径

    console.log('获取上一个页面 - prevPage:', prevPage)
    console.log('获取上一个页面的路径 - prevRoute:', prevRoute)
    console.log('获取栈顶页面 - currentPage:', currentPage)
    console.log('当前页面的路径 - currentPath:', currentPath)

    // 当前页面路径 pages/linkwifi/index
    // 上一个页面   pages/bind/index

    if ( state.discoveryStarted ) {
        state.index = 0
        stopBluetoothDevicesDiscovery();
        console.log('初始化state')
        resetState()
        // closeBluetoothAdapter()
    }
    Taro.navigateBack({})
}
</script>

<style>
    .pageContainer {
        background-color: transparent;
    }
    .navBg {
        width: 100%;
        position: absolute; /* 使用 z-index 调整上下层级需要脱离文档流 */
        top: 0;
        z-index: -100; /* z-index 设低一点，让页面元素可以覆盖它 */
    }
    .backbtn, .noBackText {
        font-family: 'siyuan', sans-serif;
        font-size: 40px;
        color: #FFF;
        position: fixed;
        top: 110px;
        left: 20px;
        display: inline-block;
        padding-left: 40px;
        background-color: transparent;
    }
    .backbtn{
        background: url(../images/back_arrow.png) no-repeat left center;
        background-size: 30%;
    } 
</style>



